var Effect = function(b: egret.DisplayObject,a,d,l = 500): egret.Tween
{
    b.x = a.x;
    b.y = a.y;
    return egret.Tween.get(b).to({
        x: d.x,
        y: d.y
    },l,egret.Ease.cubicOut);
}
class EffectUtils
{
    static rotation(c,a)
    {
        egret.Tween.get(c).to({
            rotation: 360
        },a).call(this.rotation,this,c);
    }
    static blinkEffect(b,a)
    {

    }
    static pingpong(c,a,d,l)
    {
        c.x = a.x;
        c.y = a.y;
        egret.Tween.get(c).to({
            x: d.x,
            y: d.y
        },l).call(function()
        {
            this.pingpong(c,d,a,l)
        },this);
    }
    static shake(b,a = null,d = 10,l = 10,m = 10,h = 10,g = 30)
    {
        var f = this;
        var k = b.x,
            n = b.y,
            p = m,
            q = h,
            r = function()
            {
                0 < m && (b.x = b.x != k ? k : (0.5 < Math.random() ? 1 : -1) * d + k,m-- ,d *= m / p);
                0 < h && (b.y = b.y != n ? n : (0.5 < Math.random() ? 1 : -1) * l + n,h-- ,l *= h / q)
            },
            s = function()
            {
                b.x = k;
                b.y = n;
                t.removeEventListener(egret.TimerEvent.TIMER,r,f);
                t.removeEventListener(egret.TimerEvent.TIMER_COMPLETE,s,f);
                t.stop();
                if(typeof (a) == "function")
                {
                    a();
                }
            },
            t = new egret.Timer(1E3 / g,m > h ? d : l);
        t.addEventListener(egret.TimerEvent.TIMER,r,this);
        t.addEventListener(egret.TimerEvent.TIMER_COMPLETE,s,this);
        t.start();
    }
    static gentlyPop(b,a = 300): egret.Tween
    {
        var d = b.width,
            l = b.height;
        b.alpha = 0;
        b.scaleX = 0.5;
        b.scaleY = 0.5;
        b.x += d / 4;
        b.y += l / 4;
        return egret.Tween.get(b).to({
            alpha: 1,
            scaleX: 1,
            scaleY: 1,
            x: b.x - d / 4,
            y: b.y - l / 4
        },a,egret.Ease.backOut);
    }
    static violentPop(b,a = 600)
    {
        var d = b.width,
            l = b.height;
        b.alpha = 0;
        b.scaleX = 0.5;
        b.scaleY = 0.5;
        b.x += d / 4;
        b.y +=
        l / 4;
        return egret.Tween.get(b).to({
            alpha: 1,
            scaleX: 1,
            scaleY: 1,
            x: b.x - d / 4,
            y: b.y - l / 4
        },a,egret.Ease.elasticOut);
    }
    static sliding = Effect;
    static leftSlidingIn(b: egret.DisplayObject,a = 500): egret.Tween
    {
        return Effect(b,new egret.Point(-b.width,b.y),new egret.Point(b.x,b.y),a)
    }
    static rightSlidingIn(b: egret.DisplayObject,a = 500): egret.Tween
    {
        return Effect(b,new egret.Point(WindSpirit.Util.stageW,b.y),new egret.Point(b.x,b.y),a)
    }
    static topSlidingIn(b: egret.DisplayObject,a = 500): egret.Tween
    {
        return Effect(b,new egret.Point(b.x,-b.height),new egret.Point(b.x,b.y),a)
    }
    static bottomSlidingIn(b: egret.DisplayObject,a = 500): egret.Tween
    {
        return Effect(b,new egret.Point(b.x,WindSpirit.Util.stageH),new egret.Point(b.x,b.y),a)
    }
    static leftSlidingOut(b: egret.DisplayObject,a = 500): egret.Tween
    {
        return Effect(b,new egret.Point(b.x,b.y),new egret.Point(-b.width,b.y),a)
    }
    static rightSlidingOut(b: egret.DisplayObject,a = 500): egret.Tween
    {
        return Effect(b,new egret.Point(b.x,b.y),new egret.Point(WindSpirit.Util.stageW,b.y),a)
    }
    static topSlidingOut(b: egret.DisplayObject,a = 500): egret.Tween
    {
        return Effect(b,new egret.Point(b.x,b.y),new egret.Point(b.x,-b.height),a)
    }
    static bottomSlidingOut(b: egret.DisplayObject,a = 500): egret.Tween
    {
        return Effect(b,new egret.Point(b.x,b.y),new egret.Point(b.x,WindSpirit.Util.stageH),a)
    }
    static narrowDisappear(b: egret.DisplayObject,a = 300): egret.Tween
    {
        return egret.Tween.get(b).to({
            alpha: 0,
            scaleX: 0,
            scaleY: 0,
            x: b.x + b.width / 2,
            y: b.y + b.height / 2
        },a);
    }
    static fadeIn(b: egret.DisplayObject,a = 300)
    {
        b.alpha = 0;
        return egret.Tween.get(b).to({
            alpha: 1
        },a);
    }
    static fadeOut(b: egret.DisplayObject,a = 300)
    {
        b.alpha = 1;
        return egret.Tween.get(b).to({
            alpha: 0
        },a);
    }
    static removeEffect(b: egret.DisplayObject)
    {
        egret.Tween.removeTweens(b);
    }
    static rotateLrc(obj: egret.DisplayObject,time = 1000)
    {
        obj.rotation = 0;
        var rotation = 360;
        if(Math.random() > 0.5)
        {
            rotation = -rotation;
        }
        egret.Tween.get(obj).to({
            scaleX: 1,scaleY: 1,rotation: rotation
        },time,egret.Ease.backOut);
    }
}